package com.newcapec.news.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * @Description: 字符集过滤器
 * @Author: fujun
 * @Date : 2022/3/23 10:26
 * @Version : 1.0
 * @company 新开普电子股份有限公司
 */
public class EncodingFilter implements Filter {

    private String encoding="utf-8";
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
      String encoding=  filterConfig.getInitParameter("encoding");
       if(encoding!=null){
           this.encoding=encoding;
       }
    }
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding(encoding);
        servletResponse.setCharacterEncoding(encoding);
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
